package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jy.wms.common.PinyinUtils;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.dao.ProvincialDynamicReportsMapper;
import com.jy.wms.pojo.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

@Service
public class ProvincialDynamicReportsService extends BaseService<ProvincialDynamicReportsMapper, WmsFreightStatisticsInVariousProvinces> {

    /**
     * 各省运费统计（按产品大类）
     *
     * @param
     * @return list
     */
    public JSONObject freightStatisticsInVariousProvinces(wms_ReportQuery wms_reportquery) {
        JSONObject JSON = new JSONObject();
        //拼音转换
        PinyinUtils pinyin = new PinyinUtils();
        Map<String, Object> map;
        String state = wms_reportquery.getState();
        String hzid = wms_reportquery.getHzid();
        String ckid = wms_reportquery.getCkid();

        double ZZ=0.0;
        double zyf = 0.0;//每个省的运费汇总
        //保存数据
        List<Map<String, Object>> Thenumber = new ArrayList<>();

        //判断状态是否为空
        if (state != null && !state.equals("")) {

            //单独查询出省
            PageHelper.startPage(wms_reportquery.getPage(), wms_reportquery.getRows());
            Page<WmsProvince> list = (Page<WmsProvince>) dao.freightStatisticsInVarious(wms_reportquery);

            List<WmsFreightStatisticsInVariousProvinces> Sales = null;

            //遍历省份
            for (WmsProvince sh : list) {
                //判断省份是否为空
                if (sh.getSheng() != null && !sh.getSheng().equals("")) {
                    map=new HashMap();
                    //查询运费汇总
                    String yfhz=dao.freight(hzid, ckid, state,sh.getSheng());
                    //查询该省的总运费和运费
                    Sales = dao.freightStatisticsInVariousProvinces(sh.getSheng(), state, hzid, ckid);

                        //取出种类
                        List<WmsHead> Frei = dao.WmsFreightHead(hzid, ckid);
                        //遍历种类
                        for (WmsHead use : Frei) {
                            double ljzyf = 0.0;
                            //遍历运费信息
                            for (WmsFreightStatisticsInVariousProvinces user : Sales) {

                                //获取发运订单的总重量
                                String Szzl = dao.Transportweight(user.getId());

                                //获取每个货品的总重量
                                List<WmsTotalfreightweight> Zzl = dao.Totalweightofgoods(user.getId(), use.getMc());

                                for (WmsTotalfreightweight zzl : Zzl) {

                                    double FYDZL = Double.parseDouble(Szzl);

                                    double ZZLS = Double.parseDouble(zzl.getMzzl());
                                    if (ZZLS==0.0 || FYDZL==0.0){
                                        ZZ=0.0;
                                    }else{
                                        //求百分比
                                        ZZ = ZZLS / FYDZL;
                                    }
                                    //运费
                                    double YF = Double.parseDouble(user.getZyf());
                                    //计算运费
                                    BigDecimal b = new BigDecimal(ZZ * YF);
                                    double yf = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                    //累加每个订单的该货品的运费
                                    ljzyf += yf;

                                }
                        }
                            //保存
                            String ty = pinyin.ToPinyin(use.getMc());
                            map.put(ty, ljzyf);
                    }

                    zyf= Double.parseDouble(yfhz);
                    BigDecimal b = new BigDecimal(zyf);
                    zyf = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    map.put("FreightCollection", zyf + "");
                    map.put("Province", sh.getSheng());
                    Thenumber.add(map);
                }
            }
            JSON.put("contentList", Thenumber);
            JSONArray array = JSONArray.fromObject(Thenumber);
            JSON = SetStatus.setSearchType(array.toString(), (int) list.getTotal());
        }
        return JSON;
    }


    /**
     * 各省发货支数统计（按产品大类）
     *
     * @param
     * @return list
     */
    public JSONObject thenumberofshipmentsineachprovince(wms_ReportQuery wms_reportquery) {

        PinyinUtils pinyin = new PinyinUtils();
        JSONObject JSON = new JSONObject();
        Map<String, Object> map;
        String state = wms_reportquery.getState();
        String hzid = wms_reportquery.getHzid();
        String ckid = wms_reportquery.getCkid();

        List<Map<String, Object>> Thenumber = new ArrayList<>();

        if (state != null && !state.equals("")) {
            //取出所有省份
            PageHelper.startPage(wms_reportquery.getPage(), wms_reportquery.getRows());
            Page<WmsProvince> list = (Page<WmsProvince>) dao.freightStatistics(wms_reportquery);
            //取出所有种类
            List<WmsHead> su = dao.supportnumberhead(state, hzid, ckid);

            String sheng = null;//判断省份
            int zzl = 0;//该省的支数汇总
            List<WmsShipmentsInEachProvince> Sales = null;
            String zshz = null;
            for (WmsProvince sh : list) {
                //判断省份是否为空
                if (sh.getSheng() != null && !sh.getSheng().equals("")) {
                    //查询汇总
                    if (state.equals("0")) {
                        zshz = dao.ofbranches(hzid, ckid, sh.getSheng());
                    }
                    if (state.equals("1")) {
                        zshz = dao.Already(hzid, ckid, sh.getSheng());
                    }
                    if (state.equals("2")) {
                        zshz = dao.Unshipped(hzid, ckid, sh.getSheng());
                    }
                    map = new LinkedHashMap<>();
                    for (WmsHead use : su) {
                        String type = use.getMc();
                        if (state.equals("0")) {
                            Sales = dao.thenumberofshipmentsineachprovince(hzid, ckid, sh.getSheng(), type);
                        }
                        if (state.equals("1")) {
                            Sales = dao.Alreadycount(sh.getSheng(), type, hzid, ckid);
                        }
                        if (state.equals("2")) {
                            Sales = dao.Unshippedcount(sh.getSheng(), type, hzid, ckid);
                        }

                        if (Sales.isEmpty()) {
                            map.put("Province", sh.getSheng());

                            String ty = pinyin.ToPinyin(type);
                            map.put(ty, 0);
                        }
                        for (WmsShipmentsInEachProvince user : Sales) {
                            String ty = pinyin.ToPinyin(user.getMc());
                            map.put(ty, user.getZs());

                            if (sheng == null) {
                                sheng = user.getSheng();
                                map.put("Province", sh.getSheng());
                            } else {
                                if (sheng.equals(user.getSheng())) {

                                } else if (sheng != user.getSheng()) {
                                    zzl = 0;
                                    sheng = user.getSheng();
                                    map.put("Province", sh.getSheng());
                                }
                            }
                        }
                    }
                    map.put("SupportNumberSummary", zshz);
                    Thenumber.add(map);
                }
            }
            JSON.put("contentList", Thenumber);
            JSONArray array = JSONArray.fromObject(Thenumber);
            JSON = SetStatus.setSearchType(array.toString(), (int) list.getTotal());
        }
        return JSON;
    }

    /**
     * 各省销售额统计（按产品大类）
     *
     * @param
     * @return list
     */
    public JSONObject statisticsofsalesineachprovince(wms_ReportQuery wms_reportquery) {
        Page<WmsProvince> list=new Page<>();
        JSONObject JSON = new JSONObject();
        PinyinUtils pinyin = new PinyinUtils();
        Map<String, Object> map;

        String state = wms_reportquery.getState();
        String hzid = wms_reportquery.getHzid();
        String ckid = wms_reportquery.getCkid();

        List<Map<String, Object>> Thenumber = new ArrayList<>();

        if (state != null && !state.equals("")) {
            //单独查询出省
            PageHelper.startPage(wms_reportquery.getPage(), wms_reportquery.getRows());
            list = (Page<WmsProvince>) dao.fsalesineachprovince(wms_reportquery);
            //单独查询出种类
            List<WmsHead> Salesvolume = dao.Saleshead(state, hzid, ckid);

            String sheng = null;//判断省份

            List<WmsStatisticsoFsalesIneachProvince> Sales = null;
            String xsehz = null;
            //将省份进行遍历
            for (WmsProvince sh : list) {
                //判断省份是否为空
                if (sh.getSheng() != null && sh.getSheng() != "") {

                    if (state.equals("0")) {
                        xsehz = dao.Salesvol(hzid, ckid, sh.getSheng());
                    }
                    if (state.equals("1")) {
                        xsehz = dao.Saleshav(hzid, ckid, sh.getSheng());
                    }
                    if (state.equals("2")) {
                        xsehz = dao.Unshippedsales(hzid, ckid, sh.getSheng());
                    }

                    map = new HashMap<>();
                    for (WmsHead use : Salesvolume) {
                        String type = use.getMc();
                        //根据指定省份查询出销售额
                        if (state.equals("0")) {
                            Sales = dao.statisticsofsalesineachprovince(hzid, ckid, sh.getSheng(), type);
                        }
                        if (state.equals("1")) {
                            Sales = dao.Alreadyshipped(sh.getSheng(), type, hzid, ckid);
                        }
                        if (state.equals("2")) {
                            Sales = dao.Unshippeddelivery(sh.getSheng(), type, hzid, ckid);
                        }

                        if (Sales.isEmpty()) {
                            String ty = pinyin.ToPinyin(type);
                            map.put(ty, 0);
                            map.put("Province", sh.getSheng());

                        }
                        for (WmsStatisticsoFsalesIneachProvince user : Sales) {

                            double Z = Double.parseDouble(user.getHpje());
                            BigDecimal b = new BigDecimal(Z);
                            Z = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            String ty = pinyin.ToPinyin(type);
                            map.put(ty, Z);

                            if (sheng == null) {
                                sheng = user.getSheng();
                                map.put("Province", sh.getSheng());

                            } else {
                                if (sheng.equals(user.getSheng())) {

                                } else if (sheng != user.getSheng()) {

                                    sheng = user.getSheng();
                                    map.put("Province", sh.getSheng());
                                }
                            }
                        }
                    }
                    double xse = Double.parseDouble(xsehz);
                    BigDecimal B = new BigDecimal(xse);
                    xse = B.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    map.put("SalesVolumeSummary", xse);
                    Thenumber.add(map);
                }
            }
            //System.out.println(Thenumber);
            //JSON.put("contentList", Thenumber);
        }
        JSONArray array = JSONArray.fromObject(Thenumber);
        JSON = SetStatus.setSearchType(array.toString(), (int) list.getTotal());
        return JSON;
    }

    /**
     * 各省订单量统计（按产品大类）
     *
     * @param
     * @return list
     */
    public JSONObject statisticsoforderquantityineachprovince(wms_ReportQuery wms_reportquery) {
        JSONObject JSON = new JSONObject();
        PinyinUtils pinyin = new PinyinUtils();
        Map<String, Object> map;
        Page<WmsProvince> list=new Page<>();
        String state = wms_reportquery.getState();
        String hzid = wms_reportquery.getHzid();
        String ckid = wms_reportquery.getCkid();

        List<Map<String, Object>> Thenumber = new ArrayList<>();

        if (state != null && !state.equals("")) {
            //单独查询出省
            PageHelper.startPage(wms_reportquery.getPage(), wms_reportquery.getRows());
             list = (Page<WmsProvince>) dao.statisticsoforderquantity(wms_reportquery);
            //查出所有种类
            List<WmsHead> Order = dao.Orderquantityheader(state, hzid, ckid);
            String sheng = "";//判断省份
            List<WmsShipmentsInEach> Sales = null;
            try {
                //将省份进行遍历
                for (WmsProvince sh : list) {
                    //判断省份是否为空
                    if (sh.getSheng() != null && !sh.getSheng().equals("")) {
                        //查询订单量汇总
                        Integer Query = dao.QuerySummary(hzid, ckid, state, sh.getSheng());
                        map = new HashMap<>();
                        for (WmsHead use : Order) {
                            String type = use.getMc();
                            //查询订单量
                            Sales = dao.statisticsoforderquantityineachprovince(sh.getSheng(), state, type, hzid, ckid);
                            if (Sales.isEmpty()) {
                                map.put("Province", sh.getSheng());

                                String ty = pinyin.ToPinyin(type);
                                map.put(ty, 0);
                            }
                            for (WmsShipmentsInEach user : Sales) {
                                String ty = pinyin.ToPinyin(user.getMc());
                                map.put(ty, user.getFybh());

                                if (sheng == "") {
                                    sheng = user.getSheng();
                                    map.put("Province", sh.getSheng());
                                } else {
                                    if (sheng.equals(user.getSheng())) {

                                    } else if (sheng != user.getSheng()) {
                                        String ss = sh.getSheng();
                                        if (ss.equals("")) {
                                        } else {
                                            //ddlhz = 0;
                                            sheng = user.getSheng();
                                            map.put("Province", sh.getSheng());

                                        }
                                    }
                                }
                            }
                        }
                        map.put("OrderQuantitySummary", Query);
                        Thenumber.add(map);
                    }
                }
                //JSON.put("contentList", Thenumber);

            } catch (Exception e) {
                e.getMessage();
            }
        }
        JSONArray array = JSONArray.fromObject(Thenumber);
        JSON = SetStatus.setSearchType(array.toString(), (int) list.getTotal());
        return JSON;
    }


    /**
     * 各省运费统计（按产品大类）表报导出
     *
     * @param
     * @return list
     */
    public List<Map<String, Object>> StatisticsInVariousProvinces(WmsFreightStatisticsInVariousProvinces pojo) {

        PinyinUtils pinyin = new PinyinUtils();
        Map<String, Object> map;
        String state = pojo.getState();
        String ckid = pojo.getCkid();
        String hzid = pojo.getHzid();
        double ZZ=0.0;
        double zyf = 0.0;//每个省的运费汇总
        //保存数据
        List<Map<String, Object>> Thenumber = new ArrayList<>();

        //判断状态是否为空
        if (state != null && !state.equals("")) {

            //单独查询出省
            List list = dao.freightStatisticsInVariousExport(pojo);

            List<WmsFreightStatisticsInVariousProvinces> Sales = null;

            //遍历省份
            for (int str = 0; str < list.size(); str++) {
                //判断省份是否为空
                if (list.get(str) != null && !list.get(str).equals("")) {
                    map=new HashMap();
                    //查询运费汇总
                    String yfhz=dao.freight(hzid, ckid, state,list.get(str)+"");
                    //查询该省的总运费和运费
                    Sales = dao.freightStatisticsInVariousProvinces(list.get(str)+"", state, hzid, ckid);

                    //取出种类
                    List<WmsHead> Frei = dao.WmsFreightHead(hzid, ckid);
                    //遍历种类
                    for (WmsHead use : Frei) {
                        double ljzyf = 0.0;
                        //遍历运费信息
                        for (WmsFreightStatisticsInVariousProvinces user : Sales) {

                            //获取发运订单的总重量
                            String Szzl = dao.Transportweight(user.getId());

                            //获取每个货品的总重量
                            List<WmsTotalfreightweight> Zzl = dao.Totalweightofgoods(user.getId(), use.getMc());

                            for (WmsTotalfreightweight zzl : Zzl) {

                                double FYDZL = Double.parseDouble(Szzl);

                                double ZZLS = Double.parseDouble(zzl.getMzzl());
                                if (ZZLS==0.0 || FYDZL==0.0){
                                    ZZ=0.0;
                                }else{
                                    //求百分比
                                    ZZ = ZZLS / FYDZL;
                                }
                                //运费
                                double YF = Double.parseDouble(user.getZyf());
                                //计算运费
                                BigDecimal b = new BigDecimal(ZZ * YF);
                                double yf = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                //累加每个订单的该货品的运费
                                ljzyf += yf;

                            }
                        }
                        //保存
                        String ty = pinyin.ToPinyin(use.getMc());
                        map.put(ty, ljzyf);
                    }

                    zyf= Double.parseDouble(yfhz);
                    BigDecimal b = new BigDecimal(zyf);
                    zyf = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    map.put("FreightCollection", zyf + "");
                    map.put("Province", list.get(str)+"");
                    Thenumber.add(map);
                }
            }
        }
        return Thenumber;
    }

    //运费导出报表（表头）
    public List<ExcelExportEntity> listHeader2(WmsFreightStatisticsInVariousProvinces pojo) {
        List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
        //String state = (String) mapp.get("state");

        //添加省份
        String sheng = WmsSummaryReportsOnTransportation.Province.getType();
        //拼音
        //String cpbh2=PinyinUtils.ToPinyin(sheng);
        entity.add(new ExcelExportEntity(sheng, "Province"));

        //添加运费汇总
        String huizong = WmsSummaryReportsOnTransportation.FreightCollection.getType();
        //拼音
        //String cpbh3=PinyinUtils.ToPinyin(huizong);
        entity.add(new ExcelExportEntity(huizong, "FreightCollection"));

        List<WmsHead> Frei = dao.WmsFreightHeadExport(pojo);
        System.out.println(Frei);
        for (WmsHead use : Frei) {
            String mc = use.getMc();
            //拼音
            String ddlx2 = PinyinUtils.ToPinyin(mc);
            entity.add(new ExcelExportEntity(mc, ddlx2));
        }
        return entity;
    }

    /**
     * 各省发货支数统计（按产品大类）导出
     *
     * @param
     * @return list
     */
    public List<Map<String, Object>> pmentsineachprovince(SalesInquiriesOfProvincesAndCities pojo) {

        PinyinUtils pinyin = new PinyinUtils();
        JSONObject JSON = new JSONObject();
        Map<String, Object> map;
        String ckid = pojo.getCkid();
        String hzid = pojo.getHzid();
        String state = pojo.getState();
        List<Map<String, Object>> Thenumber = new Page<>();

        if (state != null && !state.equals("")) {
            //取出所有省份
            List list = dao.freightStatisticsExport(pojo);
            //取出所有种类
            List<WmsHead> su = dao.supportnumberheadExport(pojo);

            String sheng = null;//判断省份
            String zshz = null;
            int zzl = 0;//该省的支数汇总
            List<WmsShipmentsInEachProvince> Sales = null;
            for (int str = 0; str < list.size(); str++) {
                //查询汇总
                if (state.equals("0")) {
                    zshz = dao.ofbranches(hzid, ckid, list.get(str) + "");
                }
                if (state.equals("1")) {
                    zshz = dao.Already(hzid, ckid, list.get(str) + "");
                }
                if (state.equals("2")) {
                    zshz = dao.Unshipped(hzid, ckid, list.get(str) + "");
                }
                map = new LinkedHashMap<>();
                for (WmsHead use : su) {
                    String type = use.getMc();
                    //Sales = dao.thenumberofshipmentsineachprovince(list.get(str) + "", type, hzid, ckid);
                    if (state.equals("0")) {
                        Sales = dao.thenumberofshipmentsineachprovince(hzid, ckid, list.get(str) + "", type);
                    }
                    if (state.equals("1")) {
                        Sales = dao.Alreadycount(list.get(str) + "", type, hzid, ckid);
                    }
                    if (state.equals("2")) {
                        Sales = dao.Unshippedcount(list.get(str) + "", type, hzid, ckid);
                    }
                    if (Sales.isEmpty()) {
                        map.put("Province", list.get(str));

                        String ty = pinyin.ToPinyin(type);
                        map.put(ty, 0);
                    }
                    for (WmsShipmentsInEachProvince user : Sales) {

                        String ty = pinyin.ToPinyin(user.getMc());
                        map.put(ty, user.getZs());
                        if (sheng == null) {
                            sheng = user.getSheng();
                            map.put("Province", list.get(str));
                           /* int zs = Integer.parseInt(user.getZs());
                            map.put("SupportNumberSummary", zzl += zs);*/
                        } else {
                            if (sheng.equals(user.getSheng())) {
                                /*int zs = Integer.parseInt(user.getZs());
                                map.put("SupportNumberSummary", zzl += zs);*/
                            } else if (sheng != user.getSheng()) {
                                zzl = 0;
                                sheng = user.getSheng();
                                map.put("Province", list.get(str));

                               /* int zs = Integer.parseInt(user.getZs());
                                map.put("SupportNumberSummary", zzl += zs);*/
                            }
                        }
                    }
                }
                map.put("SupportNumberSummary", zshz);
                Thenumber.add(map);
            }
        }
        System.out.println(Thenumber);
        return Thenumber;
    }

    //支数表头导出
    public List<ExcelExportEntity> zishuHeader(SalesInquiriesOfProvincesAndCities pojo) {
        List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
        String state = pojo.getState();

        //添加省份
        String sheng = WmsSummaryReportsOnTransportation.Province.getType();
        //拼音
        entity.add(new ExcelExportEntity(sheng, "Province"));
        //添加支数汇总
        String huizong = WmsSummaryReportsOnTransportation.SupportNumberSummary.getType();
        entity.add(new ExcelExportEntity(huizong, "SupportNumberSummary"));

        //取出所有种类
        List<WmsHead> su = dao.supportnumberheadExport(pojo);
        for (WmsHead use : su) {
            String mc = use.getMc();
            //拼音
            String ddlx2 = PinyinUtils.ToPinyin(mc);
            entity.add(new ExcelExportEntity(mc, ddlx2));
        }

        return entity;
    }

    /**
     * 各省销售额统计（按产品大类）导出
     *
     * @param
     * @return list
     */
    public List<Map<String, Object>> StatisticsOfTheBranches(SalesInquiriesOfProvincesAndCities pojo) {

        JSONObject JSON = new JSONObject();
        PinyinUtils pinyin = new PinyinUtils();
        Map<String, Object> map;
        String ckid = pojo.getCkid();
        String hzid = pojo.getHzid();
        String state = pojo.getState();
        List<Map<String, Object>> Thenumber = new ArrayList<>();

        if (state != null && !state.equals("")) {
            //单独查询出省
            List list = dao.fsalesineachprovinceEntity(pojo);
            //单独查询出种类
            List<WmsHead> Salesvolume = dao.SalesheadEntity(pojo);

            String mc = null;//判断规格
            String sheng = null;//判断省份
            double xse = 0.0;
            String xsehz = null;
            List<WmsStatisticsoFsalesIneachProvince> Sales = null;
            //将省份进行遍历
            for (int str = 0; str < list.size(); str++) {
                //String xsehz=dao.Salesvol(list.get(str) + "",hzid, ckid);
                if (state.equals("0")) {
                    xsehz = dao.Salesvol(hzid, ckid, list.get(str) + "");
                }
                if (state.equals("1")) {
                    xsehz = dao.Saleshav(hzid, ckid, list.get(str) + "");
                }
                if (state.equals("2")) {
                    xsehz = dao.Unshippedsales(hzid, ckid, list.get(str) + "");
                }
                map = new HashMap<>();
                for (WmsHead use : Salesvolume) {
                    String type = use.getMc();
                    //根据指定省份查询出销售额
                    //Sales = dao.statisticsofsalesineachprovince(list.get(str) + "",type, hzid, ckid);
                    if (state.equals("0")) {
                        Sales = dao.statisticsofsalesineachprovince(hzid, ckid, list.get(str) + "", type);
                    }
                    if (state.equals("1")) {
                        Sales = dao.Alreadyshipped(list.get(str) + "", type, hzid, ckid);
                    }
                    if (state.equals("2")) {
                        Sales = dao.Unshippeddelivery(list.get(str) + "", type, hzid, ckid);
                    }
                    if (Sales.isEmpty()) {

                        String ty = pinyin.ToPinyin(type);
                        map.put(ty, 0);
                        map.put("Province", list.get(str));
                    }
                    for (WmsStatisticsoFsalesIneachProvince user : Sales) {
                        //map.put("Categoryname" + d++, user.getMc());
                        double Z = Double.parseDouble(user.getHpje());
                        BigDecimal b = new BigDecimal(Z);
                        Z = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                        String ty = pinyin.ToPinyin(type);
                        map.put(ty, Z);

                        if (sheng == null) {
                            sheng = user.getSheng();
                            map.put("Province", list.get(str));
                            /*double je = Double.parseDouble(user.getHpje());
                            xse += je;
                            BigDecimal B = new BigDecimal(xse);
                            xse = B.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            map.put("SalesVolumeSummary", xse);*/
                        } else {
                            if (sheng.equals(user.getSheng())) {
                                /*double je = Double.parseDouble(user.getHpje());
                                xse += je;
                                BigDecimal B = new BigDecimal(xse);
                                xse = B.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                map.put("SalesVolumeSummary", xse);*/
                            } else if (sheng != user.getSheng()) {
                                xse = 0.0;
                                sheng = user.getSheng();
                                map.put("Province", list.get(str));

                                /*double je = Double.parseDouble(user.getHpje());
                                xse += je;
                                BigDecimal B = new BigDecimal(xse);
                                xse = B.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                map.put("SalesVolumeSummary", xse);*/
                            }
                        }
                    }
                }
                double je = Double.parseDouble(xsehz);
                xse += je;
                BigDecimal B = new BigDecimal(xse);
                xse = B.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                map.put("SalesVolumeSummary", xse);
                Thenumber.add(map);
            }
        }
        return Thenumber;
    }

    //销售额导出
    public List<ExcelExportEntity> xseHeader(SalesInquiriesOfProvincesAndCities pojo) {
        List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();

        //添加省份
        String sheng = WmsSummaryReportsOnTransportation.Province.getType();
        //拼音
        entity.add(new ExcelExportEntity(sheng, "Province"));

        //添加销售额汇总
        String huizong = WmsSummaryReportsOnTransportation.SalesVolumeSummary.getType();
        entity.add(new ExcelExportEntity(huizong, "SalesVolumeSummary"));

        //取出所有种类
        List<WmsHead> Salesvolume = dao.SalesheadEntity(pojo);
        for (WmsHead use : Salesvolume) {
            String mc = use.getMc();
            //拼音
            String ddlx2 = PinyinUtils.ToPinyin(mc);
            entity.add(new ExcelExportEntity(mc, ddlx2));
        }
        return entity;
    }

    /**
     * 各省订单量统计（按产品大类）导出
     *
     * @param
     * @return list
     */
    public List<Map<String, Object>> OrderQuantityStatistics(SalesInquiriesOfProvincesAndCities pojo) {
        JSONObject JSON = new JSONObject();
        PinyinUtils pinyin = new PinyinUtils();
        Map<String, Object> map;
        Map<String, Object> zhh = new LinkedHashMap<>();
        String ckid = pojo.getCkid();
        String hzid = pojo.getHzid();
        String state = pojo.getState();
        List<Map<String, Object>> Thenumber = new Page<>();

        if (state != null && !state.equals("")) {
            //单独查询出省
            List list = dao.statisticsoforderquantityEntity(pojo);
            //查出所有种类
            List<WmsHead> Order = dao.OrderquantityheaderEntity(pojo);
            String sheng = "";//判断省份
            int zzl = 0;//该省的所有商品的总销售额
            List<WmsShipmentsInEach> Sales = null;
            try {
                for (int str = 0; str < list.size(); str++) {
                    //查询订单量汇总
                    Integer Query = dao.QuerySummary(hzid, ckid, state, list.get(str) + "");
                    map = new HashMap<>();
                    for (WmsHead use : Order) {
                        String type = use.getMc();
                        Sales = dao.statisticsoforderquantityineachprovince(list.get(str) + "", state, type, hzid, ckid);
                        if (Sales.isEmpty()) {
                            //map.put("Categoryname" + d++, type);
                            map.put("Province", list.get(str));
                            String ty = pinyin.ToPinyin(type);
                            map.put(ty, 0);
                        }
                        for (WmsShipmentsInEach user : Sales) {
                            //map.put("Categoryname" + d++, user.getMc());
                            String ty = pinyin.ToPinyin(user.getMc());
                            map.put(ty, user.getFybh());

                            if (sheng == "") {
                                sheng = user.getSheng();
                                map.put("Province", list.get(str));
                                /*int zs = Integer.parseInt(user.getFybh());
                                map.put("OrderQuantitySummary", zzl += zs);*/
                            } else {
                                if (sheng.equals(user.getSheng())) {
                                    /*int zs = Integer.parseInt(user.getFybh());
                                    map.put("OrderQuantitySummary", zzl += zs);*/
                                } else if (sheng != user.getSheng()) {
                                    String ss = list.get(str).toString();
                                    if (ss.equals("")) {
                                        /*int zs = Integer.parseInt(user.getFybh());
                                        map.put("OrderQuantitySummary", zzl += zs);*/
                                    } else {
                                        zzl = 0;
                                        sheng = user.getSheng();
                                        map.put("Province", list.get(str));
                                        /*int zs = Integer.parseInt(user.getFybh());
                                        map.put("OrderQuantitySummary", zzl += zs);*/
                                    }
                                }
                            }
                        }
                    }
                    map.put("OrderQuantitySummary", Query);
                    Thenumber.add(map);
                }
            } catch (Exception e) {
                e.getMessage();
            }
        }
        return Thenumber;
    }

    /**
     * 各省订单量统计（按产品大类）表头导出
     *
     * @param
     * @return list
     */
    public List<ExcelExportEntity> ddlHeader(SalesInquiriesOfProvincesAndCities pojo) {
        List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
        String state = pojo.getState();

        //添加省份
        String sheng = WmsSummaryReportsOnTransportation.Province.getType();
        //拼音
        //String cpbh2=PinyinUtils.ToPinyin(sheng);
        entity.add(new ExcelExportEntity(sheng, "Province"));

        //添加订单量汇总
        String huizong = WmsSummaryReportsOnTransportation.OrderQuantitySummary.getType();
        entity.add(new ExcelExportEntity(huizong, "OrderQuantitySummary"));
        //取出所有种类
        List<WmsHead> Order = dao.OrderquantityheaderEntity(pojo);
        for (WmsHead use : Order) {
            String mc = use.getMc();
            //拼音
            String ddlx2 = PinyinUtils.ToPinyin(mc);
            entity.add(new ExcelExportEntity(mc, ddlx2));
        }

        return entity;
    }
}
